import zmq
import flatbuffers
from datetime import datetime
import SendData.SendDataSt as SendDataSt
#from SendData.SendDataSt import * # type: ignore

import time




# 创建一个 ZeroMQ 上下文
context = zmq.Context()

# 创建一个 SUB 类型的套接字
socket = context.socket(zmq.SUB)
#socket.connect("ipc:///tmp/test")
socket.connect("tcp://192.168.3.138:5558")


# 订阅所有消息
socket.setsockopt_string(zmq.SUBSCRIBE, "")

print("Subscriber started. Waiting for messages...")

# 接收并打印消息
while True:
  buf = socket.recv()
  recv_data = SendDataSt.SendDataSt.GetRootAsSendDataSt(buf, 0)

  timestamp_seconds = time.time()
  timestamp_milliseconds = int(timestamp_seconds * 1000)
  print(f"send time:{recv_data.Time()}, send size: {len(buf)}")
  print(f"recv time:{timestamp_milliseconds}")
